#Boa:Frame:LedgerFrame

import wx
import wx.grid

def create(parent):
    return LedgerFrame(parent)

[wxID_LEDGERFRAME, wxID_LEDGERFRAMEAMOUNT, wxID_LEDGERFRAMECHECKNUM, 
 wxID_LEDGERFRAMECLEAR_BUTTON, wxID_LEDGERFRAMECOMMENTS, wxID_LEDGERFRAMEDATE, 
 wxID_LEDGERFRAMEDELETE_BUTTON, wxID_LEDGERFRAMEDPCDATE, 
 wxID_LEDGERFRAMEENTER_BUTTON, wxID_LEDGERFRAMELISTVIEW1, 
 wxID_LEDGERFRAMEPAYEE, wxID_LEDGERFRAMESPLITTERWINDOW1, 
 wxID_LEDGERFRAMESTATUSBAR1, wxID_LEDGERFRAMETXTAMOUNT, 
 wxID_LEDGERFRAMETXTCHECKNUMBER, wxID_LEDGERFRAMETXTCOMMENTS, 
 wxID_LEDGERFRAMETXTPAYEE, wxID_LEDGERFRAMETYPE, wxID_LEDGERFRAMETYPEBOX, 
] = [wx.NewId() for _init_ctrls in range(19)]

[wxID_LEDGERFRAMEMENUFILECLOSE, wxID_LEDGERFRAMEMENUFILEEXIT, 
 wxID_LEDGERFRAMEMENUFILEOPEN, wxID_LEDGERFRAMEMENUFILESAVE, 
 wxID_LEDGERFRAMEMENUFILESAVEAS, 
] = [wx.NewId() for _init_coll_menuFile_Items in range(5)]

[wxID_LEDGERFRAMEMENUHELPABOUT] = [wx.NewId() for _init_coll_menuHelp_Items in range(1)]

class LedgerFrame(wx.Frame):
    
    
    def _init_coll_boxSizer7_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.txtComments, 3, border=2, flag=wx.EXPAND)
        parent.AddSizer(self.boxSizer8, 2, border=0, flag=wx.EXPAND)

    def _init_coll_boxSizer8_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.Clear_button, 1, border=3,
              flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
        parent.AddWindow(self.Delete_button, 1, border=3,
              flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
        parent.AddWindow(self.Enter_button, 1, border=3,
              flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)

    def _init_coll_boxSizer6_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.Comments, 0, border=0,
              flag=wx.ALIGN_CENTER_VERTICAL)

    def _init_coll_boxSizer4_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.Date, 1, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.Payee, 5, border=0, flag=wx.ALIGN_CENTER_VERTICAL)

    def _init_coll_boxSizer5_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.dpcDate, 1, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.txtPayee, 3, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.Amount, 1, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.txtAmount, 1, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)

    def _init_coll_boxSizer3_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.Type, 5, border=1, flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.TypeBox, 1, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.CheckNum, 1, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)
        parent.AddWindow(self.txtCheckNumber, 1, border=1,
              flag=wx.ALIGN_CENTER_VERTICAL)

    def _init_coll_boxSizer1_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.listView1, 5, border=0,
              flag=wx.GROW | wx.SHRINK | wx.EXPAND)
        parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wx.EXPAND)
        parent.AddSizer(self.boxSizer2, 2, border=0, flag=wx.SHRINK | wx.EXPAND)

    def _init_coll_boxSizer2_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer3, 1, border=0, flag=wx.SHRINK | wx.EXPAND)
        parent.AddSizer(self.boxSizer4, 1, border=0, flag=wx.SHRINK | wx.EXPAND)
        parent.AddSizer(self.boxSizer5, 1, border=0, flag=wx.SHRINK | wx.EXPAND)
        parent.AddSizer(self.boxSizer6, 1, border=0, flag=wx.SHRINK | wx.EXPAND)
        parent.AddSizer(self.boxSizer7, 2, border=2, flag=wx.SHRINK | wx.EXPAND)

    def _init_coll_menuBar1_Menus(self, parent):
        # generated method, don't edit

        parent.Append(menu=self.menuFile, title='File')
        parent.Append(menu=self.menuHelp, title='Help')

    def _init_coll_menuHelp_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='Display general information about CU Budget',
              id=wxID_LEDGERFRAMEMENUHELPABOUT, kind=wx.ITEM_NORMAL,
              text='About')
        self.Bind(wx.EVT_MENU, self.OnMenuHelpAboutMenu,
              id=wxID_LEDGERFRAMEMENUHELPABOUT)

    def _init_coll_menuFile_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='', id=wxID_LEDGERFRAMEMENUFILEOPEN,
              kind=wx.ITEM_NORMAL, text='Open')
        parent.Append(help='', id=wxID_LEDGERFRAMEMENUFILESAVE,
              kind=wx.ITEM_NORMAL, text='Save')
        parent.Append(help='', id=wxID_LEDGERFRAMEMENUFILESAVEAS,
              kind=wx.ITEM_NORMAL, text='SaveAs')
        parent.Append(help='', id=wxID_LEDGERFRAMEMENUFILECLOSE,
              kind=wx.ITEM_NORMAL, text='Close')
        parent.Append(help='', id=wxID_LEDGERFRAMEMENUFILEEXIT,
              kind=wx.ITEM_NORMAL, text='Exit')
        self.Bind(wx.EVT_MENU, self.OnMenuFileOpenMenu,
              id=wxID_LEDGERFRAMEMENUFILEOPEN)
        self.Bind(wx.EVT_MENU, self.OnMenuFileSaveMenu,
              id=wxID_LEDGERFRAMEMENUFILESAVE)
        self.Bind(wx.EVT_MENU, self.OnMenuFileSaveasMenu,
              id=wxID_LEDGERFRAMEMENUFILESAVEAS)
        self.Bind(wx.EVT_MENU, self.OnMenuFileCloseMenu,
              id=wxID_LEDGERFRAMEMENUFILECLOSE)
        self.Bind(wx.EVT_MENU, self.OnMenuFileExitMenu,
              id=wxID_LEDGERFRAMEMENUFILEEXIT)

    def _init_coll_listView1_Columns(self, parent):
        # generated method, don't edit

        parent.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT, heading='Date',
              width=95)
        parent.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT, heading='Payee',
              width=445)
        parent.InsertColumn(col=2, format=wx.LIST_FORMAT_LEFT, heading='R',
              width=25)
        parent.InsertColumn(col=3, format=wx.LIST_FORMAT_LEFT, heading='Debit',
              width=130)
        parent.InsertColumn(col=4, format=wx.LIST_FORMAT_LEFT, heading='Credit',
              width=130)
        parent.InsertColumn(col=5, format=wx.LIST_FORMAT_LEFT,
              heading='Balance', width=130)

    def _init_coll_statusBar1_Fields(self, parent):
        # generated method, don't edit
        parent.SetFieldsCount(1)

        parent.SetStatusText(number=0, text='status')

        parent.SetStatusWidths([-1])

    def _init_sizers(self):
        # generated method, don't edit
        self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer2 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer3 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer4 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer5 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer6 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer7 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer8 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self._init_coll_boxSizer1_Items(self.boxSizer1)
        self._init_coll_boxSizer2_Items(self.boxSizer2)
        self._init_coll_boxSizer3_Items(self.boxSizer3)
        self._init_coll_boxSizer4_Items(self.boxSizer4)
        self._init_coll_boxSizer5_Items(self.boxSizer5)
        self._init_coll_boxSizer6_Items(self.boxSizer6)
        self._init_coll_boxSizer7_Items(self.boxSizer7)
        self._init_coll_boxSizer8_Items(self.boxSizer8)

        self.SetSizer(self.boxSizer1)

    def _init_utils(self):
        # generated method, don't edit
        self.menuFile = wx.Menu(title='File')

        self.menuHelp = wx.Menu(title='Help')

        self.menuBar1 = wx.MenuBar()

        self._init_coll_menuFile_Items(self.menuFile)
        self._init_coll_menuHelp_Items(self.menuHelp)
        self._init_coll_menuBar1_Menus(self.menuBar1)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_LEDGERFRAME, name='LedgerFrame',
              parent=prnt, pos=wx.Point(181, 39), size=wx.Size(946, 697),
              style=wx.DEFAULT_FRAME_STYLE, title='CU Budget')
        self._init_utils()
        self.SetClientSize(wx.Size(938, 663))
        self.SetMenuBar(self.menuBar1)
        self.Bind(wx.EVT_ACTIVATE, self.OnLedgerFrameActivate)

        self.statusBar1 = wx.StatusBar(id=wxID_LEDGERFRAMESTATUSBAR1,
              name='statusBar1', parent=self, style=0)
        self._init_coll_statusBar1_Fields(self.statusBar1)
        self.SetStatusBar(self.statusBar1)

        self.Payee = wx.StaticText(id=wxID_LEDGERFRAMEPAYEE, label='Payee',
              name='Payee', parent=self, pos=wx.Point(156, 510),
              size=wx.Size(781, 19), style=0)

        self.Date = wx.StaticText(id=wxID_LEDGERFRAMEDATE, label='Date',
              name='Date', parent=self, pos=wx.Point(0, 510), size=wx.Size(156,
              19), style=0)

        self.CheckNum = wx.StaticText(id=wxID_LEDGERFRAMECHECKNUM,
              label='Check  #', name='CheckNum', parent=self, pos=wx.Point(703,
              479), size=wx.Size(117, 19), style=wx.ALIGN_CENTRE)

        self.Amount = wx.StaticText(id=wxID_LEDGERFRAMEAMOUNT,
              label='Amount  $', name='Amount', parent=self, pos=wx.Point(625,
              541), size=wx.Size(156, 19), style=wx.ALIGN_RIGHT)

        self.txtPayee = wx.TextCtrl(id=wxID_LEDGERFRAMETXTPAYEE,
              name='txtPayee', parent=self, pos=wx.Point(156, 537),
              size=wx.Size(469, 27), style=0, value='Pay Check')

        self.txtAmount = wx.TextCtrl(id=wxID_LEDGERFRAMETXTAMOUNT,
              name='txtAmount', parent=self, pos=wx.Point(781, 537),
              size=wx.Size(156, 27), style=0, value='0.00')

        self.txtCheckNumber = wx.TextCtrl(id=wxID_LEDGERFRAMETXTCHECKNUMBER,
              name='txtCheckNumber', parent=self, pos=wx.Point(820, 475),
              size=wx.Size(117, 27), style=0, value='')
        self.txtCheckNumber.Enable(False)

        self.Clear_button = wx.Button(id=wxID_LEDGERFRAMECLEAR_BUTTON,
              label='Clear', name='Clear_button', parent=self, pos=wx.Point(562,
              612), size=wx.Size(125, 33), style=wx.RAISED_BORDER)
        self.Clear_button.SetMaxSize(wx.Size(125, 33))
        self.Clear_button.Bind(wx.EVT_BUTTON, self.OnClear_buttonButton,
              id=wxID_LEDGERFRAMECLEAR_BUTTON)

        self.Enter_button = wx.Button(id=wxID_LEDGERFRAMEENTER_BUTTON,
              label='Enter', name='Enter_button', parent=self, pos=wx.Point(812,
              612), size=wx.Size(125, 33), style=wx.RAISED_BORDER)
        self.Enter_button.SetMaxSize(wx.Size(125, 33))
        self.Enter_button.Bind(wx.EVT_BUTTON, self.OnEnter_buttonButton,
              id=wxID_LEDGERFRAMEENTER_BUTTON)

        self.Comments = wx.StaticText(id=wxID_LEDGERFRAMECOMMENTS,
              label='Comments', name='Comments', parent=self, pos=wx.Point(0,
              572), size=wx.Size(76, 19), style=0)

        self.txtComments = wx.TextCtrl(id=wxID_LEDGERFRAMETXTCOMMENTS,
              name='txtComments', parent=self, pos=wx.Point(0, 597),
              size=wx.Size(562, 63), style=0, value='')

        self.dpcDate = wx.DatePickerCtrl(id=wxID_LEDGERFRAMEDPCDATE,
              name='dpcDate', parent=self, pos=wx.Point(0, 537),
              size=wx.Size(156, 27), style=wx.DP_SHOWCENTURY)
        self.dpcDate.SetLabel('4/7/2008')
        self.dpcDate.SetValue(wx.DateTimeFromDMY(7, 3, 2008, 0, 0, 0))

        self.listView1 = wx.ListView(id=wxID_LEDGERFRAMELISTVIEW1,
              name='listView1', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(938, 473), style=wx.VSCROLL | wx.LC_REPORT)
        self.listView1.SetLabel('')
        self._init_coll_listView1_Columns(self.listView1)
        self.listView1.Bind(wx.EVT_LIST_ITEM_SELECTED,
              self.OnListView1ListItemSelected, id=wxID_LEDGERFRAMELISTVIEW1)

        self.Delete_button = wx.Button(id=wxID_LEDGERFRAMEDELETE_BUTTON,
              label='Delete', name='Delete_button', parent=self,
              pos=wx.Point(687, 612), size=wx.Size(125, 33), style=0)
        self.Delete_button.SetMaxSize(wx.Size(125, 33))
        self.Delete_button.Bind(wx.EVT_BUTTON, self.OnDeleteButton,
              id=wxID_LEDGERFRAMEDELETE_BUTTON)

        self.TypeBox = wx.Choice(choices=['Deposit', 'Withdrawal', 'Debit',
              'Check'], id=wxID_LEDGERFRAMETYPEBOX, name='TypeBox', parent=self,
              pos=wx.Point(586, 475), size=wx.Size(117, 21), style=0)
        self.TypeBox.SetSelection(0)
        self.TypeBox.Bind(wx.EVT_CHOICE, self.OnTypeBoxChoice,
              id=wxID_LEDGERFRAMETYPEBOX)

        self.Type = wx.StaticText(id=wxID_LEDGERFRAMETYPE,
              label='Transaction Type  ', name='Type', parent=self,
              pos=wx.Point(0, 479), size=wx.Size(586, 19),
              style=wx.ALIGN_RIGHT)

        self.splitterWindow1 = wx.SplitterWindow(id=wxID_LEDGERFRAMESPLITTERWINDOW1,
              name='splitterWindow1', parent=self, pos=wx.Point(0, 473),
              size=wx.Size(938, 0), style=wx.SP_3D)

        self._init_sizers()

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnMenuFileOpenMenu(self, event):
        event.Skip()

    def OnMenuFileSaveMenu(self, event):
        event.Skip()

    def OnMenuFileSaveasMenu(self, event):
        event.Skip()

    def OnMenuFileCloseMenu(self, event):
        event.Skip()

    def OnMenuFileExitMenu(self, event):
        event.Skip()

    def OnMenuHelpAboutMenu(self, event):
        event.Skip()

    def OnClear_buttonButton(self, event):
        date = self.dpcDate.Label
        self.txtPayee.Value = ""
        self.txtComments.Value = ""
        self.txtCheckNumber.Value = ""
        self.txtAmount.Value = "0.00"
        self.intCurrentItem = -1
        self.TypeBox.SetSelection(0)
        self.txtCheckNumber.Enabled = False

    def OnEnter_buttonButton(self, event):
        amt = self.txtAmount.Value
        checkNum = self.txtCheckNumber.Value
        payee = self.txtPayee.Value
        
        
        try:
            amt = float(amt)
        except ValueError:
            wx.MessageBox("Amount is not numeric")
            return
        
        checkTest = str(checkNum.isdigit() or not checkNum)
        if (checkTest == "False"):
            wx.MessageBox("Check# is not numeric")
            return
        
        if (txtPayee.Value == ""):
            wx.MessageBox("Please input a Payee")
            
        date = self.dpcDate.Label
        self.listView1.InsertStringItem(self.intCurrentItemNumber, date)
        
        
        self.listView1.SetStringItem(self.intCurrentItemNumber,1, payee)
        
        self.intCurrentItemNumber += 1
        
    def OnDeleteButton(self, event):
        if (self.intCurrentItem == -1):
            return
        self.listView1.DeleteItem(self.intCurrentItem)

    def OnListView1ListItemSelected(self, event):
        self.intCurrentItem = self.listView1.GetFocusedItem()
        item = self.listView1.GetItem(self.listView1.GetFocusedItem())
        self.txtComments.Value = self.listView1.GetItemText(self.intCurrentItem)

    def OnLedgerFrameActivate(self, event):
        self.intCurrentItemNumber = 0

    def OnTypeBoxChoice(self, event):
        if (self.TypeBox.Label == "Check"):
            self.txtCheckNumber.Enabled = True
        else:
            self.txtCheckNumber.Enabled = False
